package com.esri.core.geometry;

import com.esri.core.geometry.SpatialReference;
import java.io.InvalidObjectException;
import java.io.ObjectStreamException;
import java.io.Serializable;

/* loaded from: classes.dex */
final class SpatialReferenceSerializer implements Serializable {
    private static final long serialVersionUID = 1;
    SpatialReference.Type a = SpatialReference.Type.LOCAL;
    String b = null;
    Unit c = null;

    Object readResolve() throws ObjectStreamException {
        try {
            if (this.a == SpatialReference.Type.LOCAL) {
                return SpatialReference.createLocal(this.c);
            }
            return SpatialReference.create(this.b);
        } catch (Exception unused) {
            throw new InvalidObjectException("Cannot read spatial reference from stream");
        }
    }

    public void setSpatialReferenceByValue(SpatialReference spatialReference) throws ObjectStreamException {
        try {
            SpatialReference.Type coordinateSystemType = spatialReference.getCoordinateSystemType();
            this.a = coordinateSystemType;
            if (coordinateSystemType == SpatialReference.Type.LOCAL) {
                this.c = spatialReference.getUnit();
            } else {
                this.b = spatialReference.getText();
            }
        } catch (Exception unused) {
            throw new InvalidObjectException("Cannot serialize this geometry");
        }
    }
}
